import { Inject, Get, Post, Query, Body } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { OrderMerchantEntity } from '../../entity/merchant';
import { OrderMerchantService } from '../../service/merchant';
import { OrderZhongtianService } from '../../service/zhongtian';
import { OrderTongkangService } from '../../service/tongkang';
import { OrderOrderService } from '../../service/order';

/**
 * 订单模块-店铺信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OrderMerchantEntity,
  service: OrderMerchantService
})
export class AdminOrderMerchantController extends BaseController {
  @Inject()
  orderMerchantService: OrderMerchantService;

  @Inject()
  orderOrderService: OrderOrderService;

  @Inject()
  orderZhongtianService: OrderZhongtianService;

  @Inject()
  orderTongkangService: OrderTongkangService;

  // 获取商品品类
  @Get('/getGoodsCategory')
  async getGoodsCategory() {
    return await this.orderZhongtianService.getGoodsCategory();
  }

  // 提交订单
  @Post('/submitOrder')
  async submitOrder(@Body() param) {
    return this.ok(await this.orderZhongtianService.addOrder(param));
  }

  // 提交瞳康订单
  @Post('/submitTongkangOrder')
  async submitTongkangOrder(@Body() param) {
    return this.ok(await this.orderTongkangService.addOrder(param));
  }

  // 检查瞳康名单
  @Post('/checkTongkangName')
  async checkTongkangName(@Body() param) {
    return this.ok(await this.orderTongkangService.checkOrder(param));
  }

  // 查询瞳康订单日志
  @Get('/getOrderLogs')
  async getOrderLogs(@Query() param) {
    return this.ok(await this.orderTongkangService.getOrderLogs(param));
  }

  // 同步商品
  @Get('/getGoodsType')
  async getGoodsType() {
    const result = await this.orderZhongtianService.getGoodsType();
    if (result) {
      return this.ok('同步成功');
    }
  }

  // 获取商品列表
  @Get('/getGoodsList')
  async getGoodsList(@Query() param) {
    console.log(param);
    return this.ok(await this.orderZhongtianService.getGoodsList(param));
  }

  // 查询中天订单
  @Get('/queryOrder')
  async queryOrder(@Query() param) {
    return this.ok(await this.orderZhongtianService.queryOrder(param.order_id));
  }

  // 获取瞳康商品
  @Get('/getTongkangGoodsList')
  async getTongkangGoodsList() {
    return this.ok(await this.orderTongkangService.getGoodsList());
  }

  // 获取瞳康商品
  @Get('/getTongkangGoodsListV2')
  async getTongkangGoodsListV2(@Query() param) {
    return this.ok(await this.orderTongkangService.getGoodsListV2(param));
  }

  // 获取瞳康商品
  @Get('/getTongkangGoodsListV3')
  async getTongkangGoodsListV3(@Query() param) {
    return this.ok(await this.orderTongkangService.getGoodsListV3(param));
  }

  // 获取加工列表
  @Get('/getProcessParams')
  async getProcessParams() {
    return this.ok(await this.orderTongkangService.getProcessParams());
  }

  // 获取加工列表
  @Get('/getProcessParamsV2')
  async getProcessParamsV2(@Query() param) {
    return this.ok(await this.orderTongkangService.getProcessParamsV2(param));
  }

  // 获取加工列表
  @Get('/getProcessParamsV3')
  async getProcessParamsV3(@Query() param) {
    return this.ok(await this.orderTongkangService.getProcessParamsV3(param));
  }

  // 获取加工列表
  @Get('/getProcessParamsList')
  async getProcessParamsList(@Query() param) {
    return this.ok(await this.orderTongkangService.getProcessParamsList());
  }

  // 瞳康添加订单
  @Post('/addTongkangOrder')
  async addTongkangOrder(@Body() param) {
    return this.ok(await this.orderTongkangService.addTongkangOrder(param));
  }

  // 编辑瞳康订单
  @Post('/editTongkangOrder')
  async editTongkangOrder(@Body() param) {
    return this.ok(await this.orderTongkangService.editTongkangOrder(param));
  }

  // 编辑瞳康订单
  @Post('/cancelOrder')
  async cancelOrder(@Body() param) {
    return this.ok(await this.orderTongkangService.cancelOrder(param));
  }
  

  // 添加分账接受方
  @Post('/addShareReceiver')
  async addShareReceiver(@Body() param) {
    return this.ok(await this.orderOrderService.addShareReceiver(param.merchant_id));
  }
}
